<template>
  <el-tabs>
    <el-descriptions :column="2" border>
      <el-descriptions-item label="申请标题">
        {{ detailData.title }}
      </el-descriptions-item>
      <el-descriptions-item label="领用号">
        {{ detailData.receiveCode }}
      </el-descriptions-item>
      
      <el-descriptions-item label="申请人">
        {{ detailData.userName }}
      </el-descriptions-item>
      
      <el-descriptions-item label="部门名称">
        {{ detailData.deptName }}
      </el-descriptions-item>
      
      <el-descriptions-item label="备注">
        {{ detailData.remark }}
      </el-descriptions-item>
      
    </el-descriptions>
    
  </el-tabs>
  <el-tabs v-model="activeTab" class="mt-20px" type="border-card">
    <el-tab-pane label="领用明细" name="details">
    
      <el-table :data="detailData.detailList" style="width: 100%">
        <el-table-column label="物料名称" prop="materialName" />
        <el-table-column label="物料编码" prop="materialCode" />
        <el-table-column label="物料类型" prop="materialType">
          <template #default="scope">
            <dict-tag :type="DICT_TYPE.OA_MATERIAL_TYPE" :value="scope.row.materialType" />
          </template>
        </el-table-column>
        <el-table-column label="数量" prop="quantity" />
        <el-table-column label="物料备注" prop="remark" />
      </el-table>
    </el-tab-pane>
  </el-tabs>
</template>
<script lang="ts" setup>
import { DICT_TYPE } from '@/utils/dict'
import { propTypes } from '@/utils/propTypes'
import { MaterialReceiveApi, MaterialReceiveVO } from '@/api/oa/materialreceive'

defineOptions({ name: 'OaMaterialReceiveDetail' })

const { query } = useRoute() // 查询参数
const activeTab = ref('details')

const props = defineProps({
  id: propTypes.number.def(undefined)
})
const detailLoading = ref(false) // 表单的加载中
const detailData = ref<any>({}) // 详情数据
const detailList = ref<any[]>([]) // 领用明细
const queryId = query.id as unknown as number // 从 URL 传递过来的 id 编号

/** 获得数据 */
const getInfo = async () => {
  detailLoading.value = true
  try {
    detailData.value = await MaterialReceiveApi.getMaterialReceive(props.id || queryId)
    detailList.value = detailData.value.detailList
  } finally {
    detailLoading.value = false
  }
}
defineExpose({ open: getInfo }) // 提供 open 方法，用于打开弹窗

/** 初始化 **/
onMounted(() => {
  getInfo()
})
</script>
